#include<stdio.h>
struct RGB
{
	int R;
	int G;
	int B;
};
struct data
{
	int ID;
	int x;
	int y;
	int z;
	struct RGB RGB;
};

int main()
{
	int n,k,i,j;
	scanf("%d", &n);
	struct data info[n];
	for(i = 0; i < n; i ++)
	{
		scanf("%d %d %d %d.%d.%d", &info[i].x, &info[i].y, &info[i].z, &info[i].RGB.R, &info[i].RGB.G, &info[i].RGB.B);
		info[i].ID = i+1;
	}
	
	struct data search;
	scanf("%d", &k);

	for(i = 0; i < k; i ++)
	{
		int found = 0;
		scanf("%d %d %d", &search.x, &search.y, &search.z);
		for(j = 0; j < n; j ++)
		{
			if(search.x == info[j].x && search.y == info[j].y && search.z == info[j].z)
			{
				printf("%d %03d.%03d.%03d\n", info[j].ID, info[j].RGB.R, info[j].RGB.G, info[j].RGB.B);
				found = 1;
				break;
			}
		}
		if(!found)
		{
			printf("Not Found\n");
		}
	}
	
	return 0;
}
